package com.gxa.modules.service.propertyservice.Impl;

import com.gxa.common.R;
import com.gxa.modules.mapper.propertymapper.CarBarrierMapper;
import com.gxa.modules.mapper.propertymapper.EquipmentMapper;
import com.gxa.modules.pojo.Guards;
import com.gxa.modules.pojo.GuardsAlarm;
import com.gxa.modules.pojo.GuardsPatrol;
import com.gxa.modules.service.propertyservice.CarBarrierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class CarBarrierServiceimpl implements CarBarrierService {
    @Autowired
    private CarBarrierMapper carBarrierMapper;


    /**
     * 门禁查询
     */

    @Override
    public R selectGuards(int page, int size,String device_name,String device_id,String guards_type) {
        int index=(page-1)*size;
        R r = new R();
        HashMap<Object, Object> map = new HashMap<>();
        List<Guards> guards = carBarrierMapper.selectGuards(index,size,device_name,device_id,guards_type);
        map.put("data",guards);
        int res = carBarrierMapper.selectGuardssum(index,size,device_name,device_id,guards_type);
        map.put("count",res);
        if(res > 0)
        {
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(map);
        }
        return r;
    }

    @Override
    public R addGuards(Guards guards) {
        R r = new R();
        int res = carBarrierMapper.addGuards(guards);
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("新增成功");
        }
        return r;
    }

    /**
     * 根据id修改状态
     * @param guardsTypeId
     * @return
     */
    @Override
    public R updateGuardsType(int guardsTypeId,int id) {
        R r = new R();
        int res = carBarrierMapper.updateGuardsType(guardsTypeId,id);
        r.setCode(500);
        r.setMsg("修改失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("修改成功");
        }
        return r;
    }

    /**
     * 根据id删除门禁
     * @param id
     * @return
     */
    @Override
    public R deleteGuardsById(String id) {
        R<Object> r = new R<>();

        if ( id ==null || "".equals(id) ){
            r.setCode(500);
            r.setMsg("请选择要删除的信息！");
            return r;
        }

        r.setCode(500);
        r.setMsg("删除失败！");

        if(carBarrierMapper.deleteGuardsById(id)>0){
            r.setCode(200);
            r.setMsg("删除成功！");
        }

        return r;
    }

    /**
     * 批量删除
     * @param list
     */
    @Override
    public void batchDelete(List<Integer> list) {
        carBarrierMapper.batchDelete(list);
    }

    @Override
    public R deleteGuards_patrolById(String id) {
        R<Object> r = new R<>();

        if ( id ==null || "".equals(id) ){
            r.setCode(500);
            r.setMsg("请选择要删除的信息！");
            return r;
        }

        r.setCode(500);
        r.setMsg("删除失败！");

        if(carBarrierMapper.deleteGuards_patrolById(id)>0){
            r.setCode(200);
            r.setMsg("删除成功！");
        }

        return r;

    }

    /**
     * 门禁报警查询
     */
    @Override
    public R selectGuards_alarm(int page, int size, String device_name,String device_id,String guards_alarm_type) {

        int index=(page-1)*size;
        R r = new R();
        HashMap<Object, Object> map = new HashMap<>();
        List<GuardsAlarm> guardsAlarm = carBarrierMapper.selectGuards_alarm(index,size,device_name,device_id,guards_alarm_type);
        map.put("data",guardsAlarm);
        int res = carBarrierMapper.selectGuards_alarmsum(index,size,device_name,device_id,guards_alarm_type);
        map.put("count",res);
        if(res > 0)
        {
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(map);
        }
        return r;
    }

    /**
     * 根据id删除门禁报警设备
     * @param id
     * @return
     */
    @Override
    public R deleteGuards_alarmById(String id) {
        R<Object> r = new R<>();

        if ( id ==null || "".equals(id) ){
            r.setCode(500);
            r.setMsg("请选择要删除的信息！");
            return r;
        }

        r.setCode(500);
        r.setMsg("删除失败！");

        if(carBarrierMapper.deleteGuards_alarmById(id)>0){
            r.setCode(200);
            r.setMsg("删除成功！");
        }

        return r;
    }

    /**
     * 查询门禁巡视记录
     */
    @Override
    public R selectGuards_patrol(int page, int size, String device_name,String device_id,String patrol_type) {
        R r = new R();
        int index = (page-1)*size;
        HashMap<Object, Object> map = new HashMap<>();
        List<GuardsPatrol> guardsPatrols = carBarrierMapper.selectGuards_patrol(index, size, device_name, device_id,patrol_type);
        map.put("data",guardsPatrols);
        int res = carBarrierMapper.selectGuards_patrolSum(index, size, device_name, device_id,patrol_type);
        map.put("count",res);
        if(res > 0)
        {
            r.setCode(200);
            r.setMsg("查询成功");
            r.setData(map);
        }
        return r;
    }
}
